package src.main.kotlin.day09

import java.io.File

/**
 * 类的继承与父类方法重写
 *  open关键字的使用
 *  kotlin中 class 默认是私密不可继承的
 *
 */
fun main() {
//    val p:Product = Product("marry")
    val p:Product = LuxuryProduct()
    println(p.load())
    println(p.name)

    //TODO: is 类型检测 关键字

    println(p is Product)
    println(p is LuxuryProduct)
    println(p is File)

    //Any  在kotlin中是所有类的超类
    println(p is Any)
    println(p.toString())

    //TODO: 转换  as关键字转换

    if (p is LuxuryProduct){
        println((p as LuxuryProduct).special())
//        val special = p.special()
//        println(special)
    }

}

open class Product(val name:String){
    fun description() = "Product $name"

    open fun load() = "Nothing.."
}

class LuxuryProduct : Product("Luxury"){
    //重写父类方法
    override fun load() = "LuxuryProduct loading.."

    fun special() = "luxuryProduct special function"

}